package codeTop;

import binaryTree.basic.TreeNode;

public class Class110 {

    boolean ans=true;
    public boolean isBalanced(TreeNode root) {
if (root==null){
    return ans;
}
        isBalanced(root.left);
        int h1 = getHeight(root.left);
        int h2 = getHeight(root.right);
        if (Math.abs(h1-h2)>1){
            ans=false;
            return ans;
        }
        isBalanced(root.right);

        return  ans;
    }

    public  int   getHeight(TreeNode root){
        if (root==null){
            return 0;
        }
        int d1=getHeight(root.left);
        int d2=getHeight(root.right);
        return  1+Math.max(d1,d2);

    }


    public static void main(String[] args) {
        Class110 class110 = new Class110();
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(1);
//        TreeNode treeNode3 = new TreeNode(1);
        TreeNode treeNode4 = new TreeNode(1);
//        TreeNode treeNode5 = new TreeNode(1);
//        TreeNode treeNode6 = new TreeNode(1);
        treeNode1.right=treeNode2;
//        treeNode1.right=treeNode3;
        treeNode2.right=treeNode4;

//        int height = class110.getHeight(treeNode1);
//        System.out.println(height);

        System.out.println(class110.isBalanced(treeNode1));

    }
}
